<template>
    <!--  #ifdef  H5 -->
    <web-view v-if="userInfo.id" :src="url" ref="h5WebviewRef" style="width:0px; height:0px"/>
    <!--  #endif -->
    <!--  #ifndef  H5 -->
    <web-view v-if="userInfo.id" :src="url" :fullscreen="false" @message="handleMessage" style="width:0px; height:0px"/>
    <!--  #endif -->
</template>
<script setup>
    import {computed, inject, onMounted, ref} from 'vue';
	import { useStore } from 'vuex';
	const $store = useStore();
	const $emits = defineEmits(['receiveOrder']);
	const userInfo = computed(()=> $store.state.userInfo);
	let url = ref(`/static/sseMessage.html?userId=${userInfo.value.driverId}&uri=${encodeURIComponent($store.state.serverConf.sse)}`);
	onMounted(()=>{
		if(window){
			window.addEventListener("message", handleH5Message, false);
		}
	})
	const handleH5Message = (e)=>{
		$emits('receiveOrder', e.data.data.arg)  //传给父组件index.vue
	}
	const handleMessage = (e)=>{
		$emits('receiveOrder', e.detail.data[0])  //传给父组件index.vue
	}
</script>